from PyQt5.QtWidgets import QMessageBox

from src.admin.SelectUser_UI import Ui_Form
from src.admin.AllUser_win import AllUser_Win
from src.admin.UserMsg_win import UserMsg_Win
from PyQt5 import QtWidgets


class SelectUser_Win(QtWidgets.QMainWindow,Ui_Form):
    def __init__(self, mydb,parent=None):
        super(SelectUser_Win, self).__init__(parent=parent)
        #ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('')
        #self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
        #self.setWindowIcon(icon)
        self.setupUi(self)
        self.LoginSignal=False
        self.mydb=mydb

        self.AllUser_form=AllUser_Win(self.mydb)
        self.UserMsg_form=UserMsg_Win(self.mydb)

        self.AllUser_form.setWindowTitle("全部会员信息")
        self.UserMsg_form.setWindowTitle("会员信息管理")

    def myAllUser(self):
        self.AllUser_form.myTable_init()
        self.AllUser_form.show()

    def myUserMsg(self):
        s = self.lineEdit.text()
        s = str(s)
        myselect = "SELECT * FROM usermsg WHERE usermsg.`会员号`=" + s
        try:
            mycursor = self.mydb.cursor()
            mycursor.execute(myselect)
        except Exception as a:
            QMessageBox.critical(self, '错误', '信息不正确')
        else:
            result = mycursor.fetchall()
            if len(result) == 0:
                QMessageBox.critical(self, '错误', '请输入正确的会员号')
            else:
                self.UserMsg_form.label_5.setText(str(result[0][0]))
                self.UserMsg_form.label_6.setText(result[0][1])
                self.UserMsg_form.label_9.setText(result[0][2])
                self.UserMsg_form.label_16.setText(result[0][5])
                self.UserMsg_form.label_10.setText(result[0][3])
                self.UserMsg_form.label_14.setText(result[0][4])
                self.UserMsg_form.label_18.setText(str(result[0][6]))
                self.UserMsg_form.label_19.setText(str(result[0][7]))
                self.UserMsg_form.show()


    def myOut(self):
        self.hide()

    def getmydb(self,mydb):
        self.mydb=mydb
        self.AllUser_form.getmydb(mydb)
        self.UserMsg_form.getmydb(mydb)